<?php
namespace app\index\controller;

use think\Controller;
use think\Db;

class Changepwd extends Controller
{
    public function changepwd()
    {
        $param = input('post.');
        if(empty(session('email'))){
            $this->error('请先登录!','login/login');
        }
        if(empty($param['passw1'])){
            $this->error('passw1不能为空');
        }
        if(strlen($param['passw1'])<3){
            $this->error('密码长度不能小于3');
        }
        if(empty($param['passw2'])){
            $this->error('passw2不能为空');
        }
        if($param['passw1']!=$param['passw2']) {
            $this->error('两次输入密码不一致!');
        }
        
        else{
            $result = Db::execute("update tb_member set password='" .md5($param['passw1']) . "' where email='" .session('email'). "'");
            session('email',null);
            $this->success('修改成功！请重新登陆！');
            $this->redirect(url('login/login'));
        }
    }
}

